(function() {
	var pageUtil = {
		init : function() {
			var me = this;
			$.getJSON('/account/getuserstatus', function(data) {
				if(data && data.error_no == 0) {
					me.id_card = data.data.id_card;
					me.id_card_name = data.data.id_card_name;
					me.trade_pwd_status = data.data.trade_pwd_status;
					me.mobile = data.data.mobile;
				}
				me.setIdArea();
				me.setLevelArea();
				me.setPhoneArea();
				me.setPasswdArea();
				me.setTradePasswdArea();
			});
		},
		setIdArea: function() {
			var me = this;
			popupIdVerify = function(event) {
				if(!me.idverify) {
					var IDVerify = require('home:widget/ui/idverify/idverify.js');
					me.idverify = new IDVerify();
					$('#idverify_submit').bind('click',function() {
				        var opt = me.idverify.checkForm();
				        if(!opt) {
				        	return;
				        }
				        $.post('/account/setidcard',opt,function(data) {
				            if(data && data.error_no == 0) {
				            	me.id_card = data.data.id_card;
				            	me.id_card_name = data.data.id_card_name;
				            	me.idverify.hide();
				            	me.setIdArea();
				            } else {
				            	me.idverify.setError(data.error_message);
				            }
				        },'json');
				    });
				}
				me.idverify.show();
			}
			if(me.id_card) {
				$('#user_name .ob_title').text(me.id_card_name);
				$('#user_name .ob_info').text(me.id_card);
				$('#user_name .user_info').show();
			} else {
				$('#user_name .ob_title').html('尚未进行<a id="validate_btn" class="button green_button">实名验证</a>，可能会导致账户资金风险。')
				$('#user_name .ob_info').text('');
				$('#user_name .user_info').hide();
				$('#validate_btn').bind('click',popupIdVerify);
			}
		},
		setPhoneArea : function() {
			var me = this;
			$('#tel .row_content').text(me.mobile);
			$('#tel .btn').bind('click', function() {
				alert(1);
			});
		},
		setPasswdArea : function() {
			var me = this;
			$('#passwd .btn').bind('click', function() {
				if(!me.uppwd) {
					var Uppwd = require('home:widget/ui/uppwd/uppwd.js');
					me.uppwd = new Uppwd();
				}
				me.uppwd.show();
			});
		},
		setTradePasswdArea : function() {
			var me = this;
			if(!me.trade_pwd_status || me.trade_pwd_status == 0) {
				$('#trade_passwd .row_content').text('尚未设置，请尽快设置保证账户安全。');
				$('#trade_passwd .btn').text('设置');
			}
			setComplete = function() {
				$('#trade_passwd .row_content').text('已单向加密');
				$('#trade_passwd .btn').text('修改');	
			}
			$('#trade_passwd .btn').bind('click', function() {
				if(!me.uptradepwd) {
					var Uptradepwd = require('home:widget/ui/uptradepwd/uptradepwd.js');
					me.uptradepwd = new Uptradepwd();
				}
				me.uptradepwd.show();
			});
		},
		setLevelArea : function () {
			var me = this;
			var level = 1;
			if(me.id_card) {
				level ++;
			}
			if(me.trade_pwd_status) {
				level ++;
			}
			var levelStr = '';
			switch(level) {
				case 1:
					levelStr = '低';
					break;
				case 2:
					levelStr = '中';
					break;
				case 3:
					levelStr = '高';
					break;
				default:
					levelStr = '低';
			}
			$('#security_level .status').text(levelStr);
			for (var i = 0; i < level; i++) {
				$('.security_bar').append('<li></li>');
			}
		}
	}
	pageUtil.init();
})();